package com.langchain4j.simple.config;

import com.langchain4j.simple.service.AiAssistant;
import dev.langchain4j.agent.tool.graalvm.GraalVmJavaScriptExecutionTool;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName LangChainConfig
 * @author liyang
 * @version 1.0.0
 * @createTime 12:15:00 2025/04/28
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
public class LangChainConfig {

    @Bean
    public ChatModel chatLanguageModel() {
        return OpenAiChatModel.builder()
                .apiKey(System.getenv("DASHSCOPE_KEY"))
                .modelName("qwen-turbo")
                .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .build();
    }

    @Bean
    public AiAssistant aiAssistant(ChatModel chatLanguageModel){
        val build = AiServices.builder(AiAssistant.class)
                .chatModel(chatLanguageModel)
                .tools(new GraalVmJavaScriptExecutionTool())
                .build();
        return build;
    }
}
